<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/setting.css" />
</head>

<body class="gray">
	<div class="mui-content">
	    <form class="mui-input-group" style="margin-top: 10px;">
	        <div class="mui-input-row">
	            <input type="text" class="mui-input-clear" id="phone" placeholder="请输入新的手机号码" />
	        </div>
	        <div class="mui-input-row getcode">
	            <input type="text" id="code" placeholder="请输入验证码" />
	            <a class="mui-btn bexta-btn bexta-btn-red codeBtn">获取验证码</a>
	        </div>
	    </form>
	    <div class="mui-content-padded" style="margin-top: 25px;">
			<button type="button" class="mui-btn bexta-btn bexta-btn-red mui-btn-block enter">验证</button>
	    </div>
	    
	    <p class="reTips">遇到无法解决的问题？联系客服</p>
	    
	    
	</div>
<script src="../js/mui.js"></script>
<script src="../js/bexta.js"></script>
<script type="text/javascript">
	mui.init()
	mui.plusReady(function () {
	    var views = bexta.getWebview(),	
	    		user = bexta.getStorage(USER);
	    	var phone = document.querySelector('#phone'),
	    		code = document.querySelector('#code');
	    	document.querySelector('.codeBtn').addEventListener('tap', function(){
	    		if( !check.phone(phone.value) ){
	    			mui.toast("手机号码有误");
	    			return ;
	    		}
	   		var f = mui('.codeBtn').button('loading');
			bexta.ajax(''+api.send_msg, function(res){
				if( res.isError == 0 ){
					mui.toast(res.msg);
					bexta.countDown(90, function(m){
						if( m <=1  ){
							f.reset();
						}else{
							f.setText(m + '秒');
						}
					});
				}else{
					mui.toast(res.msg);
					f.reset();
				}
			},{data:{mobile:phone.value, type:6, uid:user.uid}},function(){
				f.reset();
			});
	   });
	   
	   document.querySelector('.enter').addEventListener('tap', function(){
	   		if( !check.phone(phone.value) ){
	   			mui.toast("手机错误");
	   			return ;
	   		}
	   		if( code.value == '' ){
	   			mui.toast("验证码有误");
	   			return ;
	   		}
	   		bexta.ajax(api.change_mobile, function(res, msg){
	   			mui.toast(msg);
	   			if( !res ){
	   				bexta.rmStorage(USER);
	   				mui.later(function(){
	   					bexta.goWebview(function(){
		    					mui.fire(plus.webview.getLaunchWebview(), 'toggleClick', {
		    						path:'index2'
		    					});
		    				});
	   				}, 500)
	   			}
	   		},{data:{uid:user.uid,oldmobile:user.mobile,newmobile:phone.value, newcode:code.value,oldcode:views.codes}})
	   });
	    		document.querySelector('.reTips').addEventListener('tap', function(){
				plus.device.dial(views.calphone, true);
			}); 
	})
</script>
</body>
</html>